package com.richstonedt.smartcity.xaytsccommonms.feign;

import com.richstonedt.smartcity.xaytsccommonms.model.FileStorage;
import com.richstonedt.smartcity.xaytsccommonms.params.BatchUrlQueryParams;
import com.richstonedt.smartcity.xaytsccommonms.params.BatchUrlQueryPerfectParams;
import com.richstonedt.smartcity.xaytsccommonms.params.FileUploadParams;
import com.richstonedt.smartcity.xaytsccommonms.params.ObsFileCommonParams;
import com.richstonedt.smartcity.xaytsccommonms.vo.Result;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * <b><code>CommonFileFeign</code></b>
 * <p/>
 * Description
 * <p/>
 * <b>Creation Time:</b> 2022/5/6 16:15:01
 *
 * @author tangjiahuan
 * @since xaytsc-common-be
 */


@Component
@FeignClient(value = "xaytsc-common-rs",path = "/common-file")
public interface CommonFileFeign {
    /**
     * 文件上传
     * @param params 文件上传参数集合
     * @return 文件记录对象
     */
    @PostMapping("/uploadFile")
    Result<List<FileStorage>> uploadFile(@Validated FileUploadParams params);

    /**
     * 下载文件
     * @param params obs文件操作通用参数
     * @param response 响应对象
     */
    @PostMapping("/downloadFile")
    void downloadFile(@Validated ObsFileCommonParams params,HttpServletResponse response);

    /**
     * 删除文件
     * @param params obs文件操作通用参数
     * @return 删除结果
     */
    @DeleteMapping("/deleteFile")
    Result<String> deleteFile(@Validated ObsFileCommonParams params);

    /**
     * 批量删除
     * @param bucketName 桶名
     * @param baseUrl  桶内路径
     * @param objectKeys  对象名(图片/文件名)
     * @return 结果
     */
    @DeleteMapping("/deleteBatchFiles")
    Result<List<String>> deleteBatchFiles(@ApiParam(value = "桶名", required = true) @RequestParam("bucketName") String bucketName,
                                                 @ApiParam(value = "文件在桶内路径", required = true) @RequestParam("baseUrl") String baseUrl,
                                                 @ApiParam(value = "对象名", required = true) @RequestParam("objectKeys") List<String> objectKeys);

    /**
     * 获取临时访问权限
     * @param params 参数
     * @return 结果
     */
    @GetMapping("/getTemporarySignatureUrl")
    Result<String> getTemporarySignatureUrl(@Validated ObsFileCommonParams params);

    /**
     * 批量获取临时访问权限（不可支持 不同baseUrl）
     * @param params 参数
     * @return 结果
     */
    @GetMapping("/batchTemporarySignatureUrl")
    Result<Map<String, String>> batchTemporarySignatureUrl(@Validated BatchUrlQueryParams params);

    /**
     * 批量获取临时访问权限（支持 不同baseUrl）
     * @param params 参数
     * @return 结果
     */
    @PostMapping("/batchTemporarySignatureUrlPerfect")
    Result<Map<String, String>> batchTemporarySignatureUrlPerfect(@RequestBody @Validated BatchUrlQueryPerfectParams params);
}
